<template>
  <div>
    <MyNavcomponent title="隐私设置" />
    <!-- <van-field name="uploader" label="头像"> -->
    <!-- <van-image round width="10rem" height="10rem" :src='personInformation.avatar' /> -->
    <!-- </van-field> -->

    <van-form>
      <van-field :value="personInformation.loginName" label="账号" />
      <!-- <van-field :value="personInformation.password" type="password" label="密码" /> -->
      <van-field v-model="personInformation.userName" label="昵称" />
      <van-field v-model="personInformation.phonenumber" type="tel" label="手机号" />
      <van-field v-model="personInformation.email" type="email" label="电子邮箱" />
      <van-field
        v-model="personInformation.remark"
        rows="1"
        autosize
        label="个人简介"
        type="textarea"
        placeholder="输入你的自我介绍吧"
      />
      <div style="margin: 16px;">
        <van-button plain block type="info" native-type="submit" @click="doSubmit">确认修改信息</van-button>
        <!-- <van-button plain type="danger" @click="toLogin">退出登录</van-button> -->
        <!-- @click="doSubmit" -->
      </div>
    </van-form>
  </div>
</template>
<script>
import MyNavcomponent from "../../components/personal/MyNavcomponent";
import { getPersonInformation } from "../../api/shop-api/shop-api";
import { changePersonalInfor } from "../../api/shop-api/shop-api";
// import { uploadImg } from "../../api/shop-api/shop-api";
export default {
  name: "PersonSetUp",
  data() {
    return {
      uploader: [],
      personInformation: {}
      // file: ""
    };
  },
  created() {
    //    获取个人信息
    getPersonInformation()
      .then(res => {
        console.log(res.data);
        this.personInformation = res.data;
      })
      .catch();
  },
  methods: {
    //    getFile(event) {
    //   this.file = event.target.files[0];
    //   console.log(this.file);
    // },
    // 点击修改个人信息

    // afterRead(file) {
    //   // 此时可以自行将文件上传至服务器
    //   this.file = file;
    //   console.log(this.file);
    // },
    doSubmit(event) {
      event.preventDefault();
      let formData = new FormData();
      formData.append("userName", this.personInformation.userName);
      formData.append("phonenumber", this.personInformation.phonenumber);
      formData.append("remark", this.personInformation.remark);
      formData.append("email", this.personInformation.email);
      changePersonalInfor(formData)
        .then(res => {
          console.log(res);
        })
        .catch();
      // let formDataAvatar = new FormData();
      // formDataAvatar.append("file", this.file);
      // formDataAvatar.append("fileUseForEnum", "SHOP");
      // uploadImg(formDataAvatar)
      //   .then(res => {
      //     console.log(res);
      //   })
      //   .catch();
    }
  },
  components: {
    MyNavcomponent
  }
};
</script>
<style scoped>
</style>